#include "main.h"
#include<stdio.h>
#include<stdlib.h>
#include <malloc.h>
int init_queue(Queue **q) {
    *q = (Queue *)malloc(sizeof(Queue));
    if(*q == NULL) {
        return 1;
    }
    (*q)->size = 0;
    return 0;
}
int enqueue(Queue * q,int value) {
    if(q->size >= QUEUE_MAX_SIZE) {
        return 1;
    }
    q->elements[q->size] = value;
    q->size++;
    return 0;
}
int dequeue(Queue *q,int *value) {
    if(q->size == 0) {
        return 1;
    }
    *value = q->elements[0];
    for(int i = 0;i<q->size - 1;i++) {
        q->elements[i] = q->elements[i+1];
    }
    q->size--;
    return 0;
}
int first(Queue *q,int *value) {
    if(q->size == 0) {
        return 1;
    }
    *value = q->elements[0];
    return 0;
}
int is_empty(Queue *q) {
    return q->size == 0?0:1;
}
int size(Queue *q) {
    return q->size;
}
int main() {
    Queue *myQueue;
    int result;
    int value;
    result = init_queue(&myQueue);
    if(result !=0) {
        printf("队列初始化失败!\n");
        return 1;
    }
    for(int i=0;i<5;i++) {
        result = enqueue(myQueue,i+1);
        if (result == 1) {
            printf("入队失败：队列已满！\n");
        }
    }
    result = first(myQueue,&value);
    if(result == 0) {
        printf("队列第一个元素为:%d\n",value);
    }
    result = dequeue(myQueue,&value);
    if (result == 0) {
        printf("出队元素为：%d\n",value);
    }
    result = is_empty(myQueue);
    if(result == 0) {
        printf("队列为空！\n");
    }else {
        printf("队列不为空!\n");
    }
    int sizeResult = size(myQueue);
    printf("队列元素个数为: %d\n",sizeResult);
    free(myQueue);
    return 0;
}